<%--
  Created by IntelliJ IDEA.
  User: hp
  Date: 2025/11/7
  Time: 20:51
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="model.Employee" %>
<%@ page import="java.text.SimpleDateFormat" %>
<html>
<head>
    <title>查看员工</title>
    <link rel="stylesheet" href="<%= request.getContextPath() %>/css/style.css">
</head>
<body>
<div class="navbar">
    <div class="logo">员工信息管理系统</div>
    <div class="user-info">
        欢迎您，<%= ((model.User)session.getAttribute("loginUser")).getUsername() %> |
        <a href="${pageContext.request.contextPath}/LogoutServlet">退出登录</a>
    </div>
</div>
<div class="container">
    <div class="sidebar">
        <ul>
            <li><a href="<%= request.getContextPath() %>/DashboardServlet">仪表盘</a></li>
            <li><a href="<%= request.getContextPath() %>/EmployeeServlet?action=list">员工管理</a></li>
        </ul>
    </div>
    <div class="content">
        <div class="content-header">
            <h3>员工详情</h3>
            <a href="<%= request.getContextPath() %>/EmployeeServlet?action=list" class="btn-back">返回列表</a>
        </div>
        <div class="detail-container">
            <%
                Employee employee = (Employee) request.getAttribute("employee");
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                SimpleDateFormat sdfDateTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                if (employee == null) {
                    response.sendRedirect(request.getContextPath() + "/EmployeeServlet?action=list");
                    return;
                }
            %>
            <div class="detail-item">
                <label>ID：</label>
                <span><%= employee.getId() %></span>
            </div>
            <div class="detail-item">
                <label>姓名：</label>
                <span><%= employee.getName() %></span>
            </div>
            <div class="detail-item">
                <label>部门：</label>
                <span><%= employee.getDepartment() %></span>
            </div>
            <div class="detail-item">
                <label>职位：</label>
                <span><%= employee.getPosition() %></span>
            </div>
            <div class="detail-item">
                <label>薪资：</label>
                <span><%= String.format("%.2f", employee.getSalary()) %> 元</span>
            </div>
            <div class="detail-item">
                <label>邮箱：</label>
                <span><%= employee.getEmail() != null ? employee.getEmail() : "无" %></span>
            </div>
            <div class="detail-item">
                <label>电话：</label>
                <span><%= employee.getPhone() != null ? employee.getPhone() : "无" %></span>
            </div>
            <div class="detail-item">
                <label>入职日期：</label>
                <span><%= sdf.format(employee.getHireDate()) %></span>
            </div>
            <div class="detail-item">
                <label>创建时间：</label>
                <span><%= sdfDateTime.format(employee.getCreatedAt()) %></span>
            </div>
            <div class="detail-item">
                <label>最后更新：</label>
                <span><%= sdfDateTime.format(employee.getUpdatedAt()) %></span>
            </div>
            <div class="detail-actions">
                <a href="<%= request.getContextPath() %>/EmployeeServlet?action=edit&id=<%= employee.getId() %>" class="btn-edit">编辑</a>
                <a href="<%= request.getContextPath() %>/EmployeeServlet?action=delete&id=<%= employee.getId() %>" class="btn-delete" onclick="return confirm('确定要删除吗？')">删除</a>
            </div>
        </div>
    </div>
</div>
</body>
</html>
